class code4_2 {
    //有序
    public int searchInsert(int[] nums, int target) {
        int left = 0;
        int right = nums.length-1;

        while(left < right) {
            int mid = left + (right-left)/2;

            if(nums[mid] >= target) {
                right = mid;
            } else {
                left = mid+1;
            }
        }
        //特殊情况
        if(nums[right] < target) return left+1;

        return left;
    }
}